#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int num;
struct piihash {
  template <class T1, class T2>
  std::size_t operator()(const std::pair<T1, T2>& p) const {
    auto h1 = std::hash<T1>{}(p.first);
    auto h2 = std::hash<T2>{}(p.second);
    return h1 ^ h2;
  }
};
unordered_set<pii, piihash> vis;
pii a[N];
int test = 0;
void bfs(int sx, int sy) {
  queue<pii> q;
  vis.insert(pii(sx, sy));
  q.push(pii(sx, sy));
  while (q.size()) {
    pii now = q.front();
    q.pop();
    int x = now.first, y = now.second;
    // four dirs
    if (x > 1 && y > 1) {
      int d = min(x - 1, y - 1);
      int nx = x - d, ny = y - d;
      test++;
      if (!vis.count(pii(nx, ny))) {
        vis.insert(pii(nx, ny));
        q.push(pii(nx, ny));
      }
    }
    if (x > 1 && y < m) {
      int d = min(x - 1, m - y);
      int nx = x - d, ny = y + d;
      test++;
      if (!vis.count(pii(nx, ny))) {
        vis.insert(pii(nx, ny));
        q.push(pii(nx, ny));
      }
    }
    if (x < n && y > 1) {
      int d = min(n - x, y - 1);
      int nx = x + d, ny = y - d;
      test++;
      if (!vis.count(pii(nx, ny))) {
        vis.insert(pii(nx, ny));
        q.push(pii(nx, ny));
      }
    }
    if (x < n && y < m) {
      int d = min(n - x, m - y);
      int nx = x + d, ny = y + d;
      test++;
      if (!vis.count(pii(nx, ny))) {
        vis.insert(pii(nx, ny));
        q.push(pii(nx, ny));
      }
    }
  }
}
void solve() {
  cin >> n >> m;
  // only considering the cells on the edge
  int cnt = 0;
  rep(i, 1, m) {
    if (!vis.count(pii(1, i))) cnt++, bfs(1, i);
    if (!vis.count(pii(n, i))) cnt++, bfs(n, i);
  }
  rep(i, 1, n) {  // 2 .. n - 1 also works
    if (!vis.count(pii(i, 1))) cnt++, bfs(i, 1);
    if (!vis.count(pii(i, m))) cnt++, bfs(i, m);
  }
  cout << cnt << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}